<template>
  <div class="member-order">
    <!-- <h2>订单列表</h2>
    <XtxTabs v-model="activeName" @tab-click ="handlerClick" >
      <XtxTabsPanel label="11" name="44">77</XtxTabsPanel>
      <XtxTabsPanel label="22" name="55">88</XtxTabsPanel>
      <XtxTabsPanel label="33" name="66">99</XtxTabsPanel>
    </XtxTabs> -->
  </div>
  <div class="member-order-page">
    <XtxTabs v-model="activeName" @tab-click="handlerClick">
      <XtxTabsPanel
        v-for="item in orderStatus"
        :key="item.name"
        :label="item.label"
        :name="item.name"
      >
        <!-- {{ item.label }} -->
        <!-- 订单详情数据 -->
        <!--把遍历后的 所有item数据传到抽离的组件中使用 -->
        <div class="order-list">
          <OrderItem v-for="item in orderList" :key="item.id" :order="item" />
        </div>
      </XtxTabsPanel>
    </XtxTabs>
  </div>
</template>
<script>
import { reactive, ref, watch } from 'vue'
// 导入封装的 orderStatus
import { orderStatus } from '@/constants/order'
import { reqFindOrderList } from '@/api/order'
import OrderItem from './components/order-item.vue'
export default {
  components: { OrderItem },
  name: 'MemberOrder',
  setup () {
    const activeName = ref('all')
    // 订单列表
    const orderList = ref([])
    // 查询订单参数
    const requestParams = reactive({
      orderState: 0,
      page: 1,
      pageSize: 5
    })

    // 点击tabs栏的处理事件
    const handlerClick = (val) => {
      // console.log('tabS被点击了', val)
      requestParams.orderState = val.index
    }
    // 监听requestParams数据的变化，重新从服务器获取数据
    watch(requestParams, () => {
      // 接口获取数据
      reqFindOrderList(requestParams).then(({ result }) => {
        // 数据在 items字段中
        // console.log('订单数据', result)
        orderList.value = result.items
        console.log('订单列表', orderList)
      })
      // 进入页面先发送请求获取数据
    }, { immediate: true })
    return { activeName, handlerClick, orderStatus, requestParams, orderList }
  }
}
</script>
<style scoped lang="less">
.order-list {
  background: #fff;
  padding: 20px;
}
</style>
